package caom.wangs.java8.lamda;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class CHUANBINGDemo {

    @Test
    public void test1() {
        Stream.of(3, 4, 5, 2, 34, 433, 33).filter(s -> {
            System.out.println(Thread.currentThread() + " " + s);
            return s > 3;
        }).count();
    }

    @Test
    public void test111() {
        Stream.of(3, 4, 5, 2, 34, 433, 33)
                .parallel()
                .filter(s -> {
                    System.out.println(Thread.currentThread() + " " + s);
                    return s > 3;
                }).count();
    }

    @Test
    public void test11() {
        Stream.of(3, 4, 5, 2, 34, 433, 33)
                .parallel()
                .filter(s -> {
                    System.out.println(Thread.currentThread() + " " + s);
                    return s > 3;
                }).count();
    }


    @Test
    public void test2() {
        List<Integer> list = new ArrayList<>();
        Stream<Integer> integerStream = list.parallelStream();
        //通过list接口直接获取并行流

        //将已有 的串行流 转换为并行流
        Stream<Integer> parallel = Stream.of(1, 2, 3).parallel();

    }
}
